import axios from "axios";
import { encryParams } from "./tools";

window.jumpTo = (url, id) => {
  var params = { id };
  var urlParams = encryParams(params);
  axios
    .request({
      method: "POST",
      url: "http://webapp.develop.com/adserver/api/reportinfo",
      data: urlParams
    })
    .then(function(response) {
      var _response$data = response.data;
      console.log(_response$data);
    })
    .catch(function(error) {
      console.log(error);
    });

  window.location.href = url;
};

// 倒计时
let time = 15; // 15秒倒计时
const clock = document.getElementById("clock");
const timer = setInterval(() => {
  time -= 1;
  if (time === 0) {
    timer && clearInterval(timer);
    // TODO
  }
  clock.innerText = `${time}秒`;
}, 1000);

// 获取右上角按钮点击事件
const button = document.getElementById("button");
button.onclick = () => {
  timer && clearInterval(timer);
  console.log("button onclick ... ...");
  // TODO
};
